# -*- coding: utf-8 -*-

"""
@IDE: PyCharm
@FileName: Tree
@Author: JYFelt
@date： 201801102301 
@这里写描述：
"""
__author__ = 'JYFelt'

# Tree
# The simple Tree

Tree1 = [2, 3, [58, 6, [5]]]
# print(Tree[0])
# print(Tree[1])
# print(Tree[2])
Tree2 = Tree1[2]
print(Tree2[0])

# 二叉树的构造
"""
        7
    //     \\
    8       9
      \\      \\
       23      36
    //    \\
    57    58  

分析：

-*- jd == 节点
节点名= （L_child，   R_child，   节点）
base = (-->8(jd2),  -->9(jd3),  7)
jd2  = (no,         -->23(jd4), 8)
jd3  = (no,         -->36(jd5), 9)
jd4  = (-->57(jd6), -->58(jd7), 23)
jd5  = (no,         no,         36)
jd6  = (no,         no,         57)
jd7  = (no,         no,         58)

"""


class Tree():
    def __init__(self, leftjd=0, rightjd=0, data=0):
        self.leftjd = leftjd
        self.rightjd = rightjd
        self.data = data


class Btree():
    def __init__(self, base=0):
        self.base = base

    def empty(self):
        if self.base is 0:
            return True
        else:
            return False

    def qout(self, jd):
        """前序遍历,NLR,根左右"""
        if jd == 0:
            return

        print(jd.data)
        self.qout(jd.leftjd)
        self.qout(jd.rightjd)

    def mout(self, jd):
        """中序遍历,LNR,左根右"""
        if jd == 0:
            return

        self.mout(jd.leftjd)
        print(jd.data)
        self.mout(jd.rightjd)

    def hout(self, jd):
        """后序遍历,RLN,左右根"""
        if jd == 0:
            return

        self.hout(jd.letfjd)
        self.hout(jd.rightjd)
        print(jd.data)


jd1 = Tree(data=8)
jd2 = Tree(data=9)
base = Tree(jd1, jd2, 7)
x = Btree(base)
print("前序遍历,NLR,根左右")
x.qout(x.base)
print("中序遍历,LNR,左根右")
x.mout(x.base)